<template>
  <el-dialog
      :close-on-click-modal="false"
      :visible.sync="searchVisibleuse"
      :before-close="handleClose"
      style="margin-top:8vh !important"
    >
    <template slot="title">
        <div :style="titleColor">搜索</div>
      </template>
      <el-form :inline="true" class="demo-form-inline filter">
        <el-form-item label="人员">
          <el-input
            v-model="listQuerySearchuse.username"
            clearable
            class="filter-item"
            placeholder="请输入人员"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            round
            size="medium"
            class="filter-item"
           :style="{background:buttonColor.lookup,color:buttonColor.color}"
            @click="searchFilteruse"
          >查找</el-button
          >
        </el-form-item>
      </el-form>

      <!-- 查询结果 -->
      <el-table
        v-loading="listLoadingSearchuse"
        :data="searchListuse"
        :header-cell-style="tableColor"
        stripe
        element-loading-text="正在查询中。。。"
        border
        fit
        highlight-current-row
        height="300"
      >
        <el-table-column align="center" label="账号" prop="id" />
        <el-table-column align="center" label="人员" prop="username" />
        <el-table-column
          align="center"
          label="选择"
          class-name="small-padding"
        >
          <template slot-scope="scope">
            <el-button
              :style="{background:buttonColor.confirm,color:buttonColor.color}"
              round
              size="small"
              class="button-margin"
              @click="searchDatause(scope.row)"
            >确定</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totalSearchuse > 0"
        :total="totalSearchuse"
        :page.sync="listQuerySearchuse.page"
        :limit.sync="listQuerySearchuse.limit"
        style="padding:14px 10px !important"
        @pagination="getSearchListuse"
      />
    </el-dialog>
</template>

<script>
import { listAdmin } from '@/api/admin'
import Pagination from '@/components/Pagination'
import {buttonColor,titleColor} from '@/filters/index'
export default {
  name: 'UserDialog',
  components: { Pagination },
  props:{
    searchVisibleuse: {
      required: true,
      type: Boolean
    },
    tableColor: {
      required: true,
      type: Object
    },
    fsiteNo: {
      required: true,
    },
  },
  data(){
    return{
      titleColor,
      buttonColor,
      searchListuse: null,
      listLoadingSearchuse: true,
      totalSearchuse: 0,
      listQuerySearchuse: {
        page: 1,
        limit: 20,
        fpointName: undefined,
        sort: 'create_time',
        order: 'desc'
      },

      searchFlaguse:'',
    }
  },
  created() {
    this.getSearchListuse()
  },
  watch: {
    fsiteNo: function() {
      this.getSearchListuse()
    },
  },
  methods: {
     // 人员弹出框
    getSearchListuse() {
      if(this.fsiteNo){
        this.listLoadingSearchuse = true
        const templ={
          fsiteNoBelong:this.fsiteNo,
          page:this.listQuerySearchuse.page,
           limit:this.listQuerySearchuse.limit,
           sort: 'create_time',
           order: 'desc',
           username:this.listQuerySearchuse.username,
        }
       listAdmin(templ)
      .then(response => {
        this.searchListuse = response.data.data.list
        this.totalSearchuse = response.data.data.total
          this.listLoadingSearchuse = false
      })
      .catch(() => {
        this.searchListuse = []
        this.totalSearchuse = 0
          this.listLoadingSearchuse = false
      })
      }else{
        this.searchListuse = []
        this.totalSearchuse = 0
          this.listLoadingSearchuse = false
      }

    },

    // 查找
    searchFilteruse() {
      this.listQuerySearchuse.page = 1
      this.getSearchListuse()
    },

    // 确定
    searchDatause(row) {
       this.$emit('update:searchVisibleuse', false)
      this.$emit('userDialog', { user: row })
    },

    // 弹窗点击关闭前的回调
    handleClose(){
      this.$emit('update:searchVisibleuse', false)
    }

  }
}
</script>
